package com.zhuqi.message.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * <p>类描述</p>
 * Copyright: Copyright (C) 2023 YinTa, Inc. All rights reserved.
 * @author zhuqi
 * @since 2023/4/13 9:41
 */
@Configuration
public class RedisConfig {

	@Bean
	public RedisTemplate<String,String> pubSubStrRedisTemplate(RedisConnectionFactory factory) {
		RedisTemplate<String,String> redisTemplate = new RedisTemplate<>();
		redisTemplate.setConnectionFactory(factory);
		// 设置简单 key 和 value 的序列化器
		redisTemplate.setKeySerializer(new StringRedisSerializer());
		redisTemplate.setValueSerializer(new StringRedisSerializer());
		// 设置 hash 的 key 和 value 的序列化器
		redisTemplate.setHashValueSerializer(new StringRedisSerializer());
		redisTemplate.setHashValueSerializer(new StringRedisSerializer());
		redisTemplate.afterPropertiesSet();
		return redisTemplate;
	}
}
